package net.yeah.chungchizhang.minecraft.mirrorsite;

import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;

public class SingleThreadDownload implements Runnable{

    public String URLTEMP;
    public String FILENAMETMP;

    public void run () {
        Download(URLTEMP, FILENAMETMP);
    }
    public void Download(String URL, String FileName) {
        try (BufferedInputStream inputStream = new BufferedInputStream(new URL(URL).openStream());
             FileOutputStream fileOS = new FileOutputStream(FileName)) {
            byte data[] = new byte[1024];
            int byteContent;
            while ((byteContent = inputStream.read(data, 0, 1024)) != -1) {
                fileOS.write(data, 0, byteContent);
            }
        } catch (IOException e) {
            // handles IO exceptions
        }
    }
}
